<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      #cs {
        border: 1px solid #999;
      }
    </style>
  </head>
  <body>
    <canvas id="cs" width="400px" height="400px">您的浏览器不支持canvas</canvas>
  </body>
  <script>
    var cs = document.getElementById("cs");
    if (cs.getContext("2d")) {
      var ctx = cs.getContext("2d");
      ctx.font = "40px 楷体"; //设置字体大小和样式，必须给两个参数
      ctx.strokeStyle = "pink"; //注意：样式设置要放在绘制之前
      ctx.fillStyle = "red";
      ctx.textAlign = "left";//设置对齐方式
      ctx.textBaseline = "bottom";//设置基线
      // ctx.fillText("好好学习，天天向上!",100,100)
      // ctx.fillText("好好学习，天天向上!", 100, 100, 180);
      ctx.fillText("好好学习，天天向上!", 10, 100);
      ctx.strokeText("好好学习，天天向上！", 10, 200);
    } else {
      console.log("您的浏览器不支持canvas");
    }
  </script>
</html>
